package persistence;
import java.util.*;
import java.io.*;

public class EventTDG 
{
	//member variables
	
	
	//methods
	public static ArrayList<EventFascade> FindAll()
	{
		ArrayList<EventFascade> EventsFascade = new ArrayList<EventFascade>(30);
		
		FileStorageRegistry.GetInstance().CheckFilesExist("src/events.txt");
		
		File events = new File("src/events.txt");

        try 
        {
        	BufferedReader reader = new BufferedReader(new FileReader(events));
        	String EventName="";
        	String StartDate="";
        	String EndDate="";
        	String MaxCapacity="";
        	String Status="";
        	String HallID="";
        	
        	while(reader.ready())
        	{
        		EventName = reader.readLine();
        		StartDate = reader.readLine();
        		EndDate = reader.readLine();
        		MaxCapacity = reader.readLine();
        		Status = reader.readLine();
        		HallID = reader.readLine();
        		
        		int StartYear = Integer.parseInt(StartDate.substring(0,4))-1900;
        		int StartMonth = Integer.parseInt(StartDate.substring(5,7));
        		int StartDay = Integer.parseInt(StartDate.substring(8,10));
        		int StartHour = Integer.parseInt(StartDate.substring(13,15));
        		int StartMinute = Integer.parseInt(StartDate.substring(16,18));
        		
        		int EndYear = Integer.parseInt(EndDate.substring(0,4))-1900;
        		int EndMonth = Integer.parseInt(EndDate.substring(5,7));
        		int EndDay = Integer.parseInt( EndDate.substring(8,10));
        		int EndHour = Integer.parseInt(EndDate.substring(13,15));
        		int EndMinute = Integer.parseInt(EndDate.substring(16,18));
        	
        		
        		if(Status=="open")
        		{
        			EventsFascade.add(new EventFascade(EventName, new Date(StartYear,StartMonth,StartDay,StartHour,StartMinute) ,new Date(EndYear,EndMonth,EndDay, EndHour,EndMinute),Integer.parseInt(MaxCapacity),true,Integer.parseInt(HallID)));
        		}
        		
        		else
        		{
        			EventsFascade.add(new EventFascade(EventName, new Date(StartYear,StartMonth,StartDay,StartHour,StartMinute) ,new Date(EndYear,EndMonth,EndDay, EndHour,EndMinute),Integer.parseInt(MaxCapacity),false,Integer.parseInt(HallID)));
        		}
        		
        		reader.readLine(); //skips past '-' of txt file
        	}
        	
        	
        	reader.close();
        } 
        
        catch (Exception e) 
        {
            System.err.println(e);
            System.exit(1);
        }
		
		return EventsFascade;
	}
	
}
